package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DemandInfo;
import com.ruoyi.system.service.IDemandInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 需求信息库Controller
 * 
 * @author ruoyi
 * @date 2025-11-10
 */
@Controller
@RequestMapping("/business/DemandInfo")
public class DemandInfoController extends BaseController
{
    private String prefix = "business/DemandInfo";

    @Autowired
    private IDemandInfoService demandInfoService;

    @RequiresPermissions("business:DemandInfo:view")
    @GetMapping()
    public String DemandInfo()
    {
        return prefix + "/DemandInfo";
    }

    /**
     * 查询需求信息库列表
     */
    @RequiresPermissions("business:DemandInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DemandInfo demandInfo)
    {
        startPage();
        List<DemandInfo> list = demandInfoService.selectDemandInfoList(demandInfo);
        return getDataTable(list);
    }

    /**
     * 导出需求信息库列表
     */
    @RequiresPermissions("business:DemandInfo:export")
    @Log(title = "需求信息库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DemandInfo demandInfo)
    {
        List<DemandInfo> list = demandInfoService.selectDemandInfoList(demandInfo);
        ExcelUtil<DemandInfo> util = new ExcelUtil<DemandInfo>(DemandInfo.class);
        return util.exportExcel(list, "需求信息库数据");
    }

    /**
     * 新增需求信息库
     */
    @RequiresPermissions("business:DemandInfo:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存需求信息库
     */
    @RequiresPermissions("business:DemandInfo:add")
    @Log(title = "需求信息库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DemandInfo demandInfo)
    {
        return toAjax(demandInfoService.insertDemandInfo(demandInfo));
    }

    /**
     * 修改需求信息库
     */
    @RequiresPermissions("business:DemandInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DemandInfo demandInfo = demandInfoService.selectDemandInfoById(id);
        mmap.put("demandInfo", demandInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存需求信息库
     */
    @RequiresPermissions("business:DemandInfo:edit")
    @Log(title = "需求信息库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DemandInfo demandInfo)
    {
        return toAjax(demandInfoService.updateDemandInfo(demandInfo));
    }

    /**
     * 删除需求信息库
     */
    @RequiresPermissions("business:DemandInfo:remove")
    @Log(title = "需求信息库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(demandInfoService.deleteDemandInfoByIds(ids));
    }
}
